<template>
  <el-card shadow="never" class="aui-card--fill">
    <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataLists()"
      >
        <el-form-item label="产品名称">
          <el-input
            v-model="dataForm.productLineName"
            placeholder="请输入产品名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item >
            <el-select v-model="dataForm.status" clearable  placeholder="请选择状态">
              <el-option
                v-for="item in typeList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataLists()">{{ $t("query") }}</el-button>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="danger" @click="deleteHandleLS('','Batch')">删除</el-button>
          </el-form-item>
      </el-form>
    <div class="mod-sys__dept">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataLists()">
        <el-form-item>
          <el-button v-if="$hasPermission('sys:dept:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" row-key="id" border style="width: 100%;" @selection-change="dataListSelectionChangeHandle"
        @sort-change="dataListSortChangeHandle">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column type="index" header-align="center" align="center" label="序号" width="50"></el-table-column>
        <el-table-column prop="productLineName" label="产品线名称" header-align="center"  align="center"></el-table-column>
        <el-table-column prop="sort" label="排序" header-align="center" align="center"></el-table-column>
        <el-table-column prop="status" label="状态" header-align="center" align="center" >
            <template slot-scope="scope">
                {{ scope.row.status === 1?'显示':"隐藏"  }}
            </template>
        </el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button  type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">编辑</el-button>
            <el-button  type="text" size="small" @click="deleteHandleLS(scope.row.id,'single')">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataLists"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './productLine-addorUpdate'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
        typeList:[
        {
          name:"隐藏",
          id:0
        },
        {
          name:"显示",
          id:1
        },
      ],
      page:1,
      limit:10,
      dataForm:{
        productLineName:"",
        status:""
      },
      mixinViewModuleOptions: {
        createdIsNeed: false,       // 此页面是否在创建时，调用查询数据列表接口？
        // deleteURL: '/productLine/delete',
        // deleteIsBatch: true,
       
      },
      mixin: {
        getDataListURL: '/productLine/page',
      }
    }
  },
  created(){
    this.queryList()
  },
  components: {
    AddOrUpdate
  },
  methods:{
    getDataLists: function () {
      this.page = 1
      this.queryList()
    },
    deleteHandleLS (id,batch) {
      var formData = new FormData(); // 当前为空
      if(batch =='Batch'){
        let Ids = []
        Ids = this.dataListSelections.map(item=>{
          return  item.id
        })
        formData.append('ids',Ids)
      }else{
        let idChange = String(id)
        formData.append('ids', [idChange]);
      }
      this.$confirm(this.$t('prompt.info', { 'handle': this.$t('delete') }), this.$t('prompt.title'), {
        confirmButtonText: this.$t('confirm'),
        cancelButtonText: this.$t('cancel'),
        type: 'warning'
      }).then(() => {
        this.$http.post(
          "/productLine/delete", formData,
          {
          headers: {
            "Content-Type": "multipart/form-data",
          },
        }
        ).then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.$message({
            message: this.$t('prompt.success'),
            type: 'success',
            duration: 500,
            onClose: () => {
              this.queryList()
            }
          })
        }).catch(() => {})
      }).catch(() => {})
    },
    queryList () {
      this.dataListLoading = true
      this.$http.get(
        this.mixin.getDataListURL,
        {
          params: {
            
            page:  this.page,
            limit:this.limit,
            ...this.dataForm
          }
        }
      ).then(({ data: res }) => {
        this.dataListLoading = false
        if (res.code !== 0) {
          this.dataList = []
          this.total = 0
          return this.$message.error(res.msg)
        }
       
        this.dataList = res.data.list 
        this.total = res.data.total 
      }).catch(() => {
        this.dataListLoading = false
      })
    },
  }
}
</script>
